package com.cjh.lms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cjh.lms.mapper.TClientMapper;
import com.cjh.lms.mapper.TLockInfoMapper;
import com.cjh.lms.mapper.TReqMapper;
import com.cjh.lms.mapper.business.ClientInfoMapper;
import com.cjh.lms.mapper.business.ShowCheckListMapper;
import com.cjh.lms.pojo.TClient;
import com.cjh.lms.pojo.TClientExample;
import com.cjh.lms.pojo.TLockInfoExample;
import com.cjh.lms.pojo.TReq;
import com.cjh.lms.pojo.TReqExample;
import com.cjh.lms.pojo.TReqExample.Criteria;
import com.cjh.lms.pojo.business.LockCheckModel;
import com.cjh.lms.pojo.business.LockClientModel;

@Service("AllocationManageService")
public class AllocationManageService {
	@Autowired
	TReqMapper tReqMapper;

	@Autowired
	TLockInfoMapper tLockInfoMapper;
	@Autowired
	TClientMapper tClientMapper;
	@Autowired
	ShowCheckListMapper showCheckListMapper;
	@Autowired
	ClientInfoMapper clientInfoMapper;

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}

	public int addRequest(TReq tReq) {
		return tReqMapper.insert(tReq);
	}

	public boolean selectByCcode(String cCode) {
		TReqExample tReqExample = new TReqExample();
		Criteria createCriteria = tReqExample.createCriteria();
		createCriteria.andCCodeEqualTo(cCode);
		List<TReq> tReqs = tReqMapper.selectByExample(tReqExample);
		for(int i=0;i<tReqs.size();i++){
		if(tReqs.get(i).getState()==0)
				return false;
		}
		return true;
	}

	public void checkRequest(String rCode) {

	}

	public List<TReq> selectByRCode(String rCode) {
		TReqExample tReqExample = new TReqExample();
		Criteria createCriteria = tReqExample.createCriteria();
		createCriteria.andRCodeEqualTo(rCode);
		return tReqMapper.selectByExample(tReqExample);
	}

	public long countLock() {
		TLockInfoExample tLockInfoExample = new TLockInfoExample();
		com.cjh.lms.pojo.TLockInfoExample.Criteria createCriteria = tLockInfoExample.createCriteria();
		createCriteria.andStateEqualTo(0);
		return tLockInfoMapper.countByExample(tLockInfoExample);
	}

	public void updateByState() {

	}

	public void updateByRCode() {

	}

	public void updateByTid() {

	}

	public void updateState() {

	}

	public void updateStateByRCode(String rCode) {

	}

	public void updateState(TReq tReq) {
		tReqMapper.updateByPrimaryKey(tReq);
	}

	public List<TReq> selectToBeChecked() {
		TReqExample tReqExample = new TReqExample();
		Criteria createCriteria = tReqExample.createCriteria();
		createCriteria.andStateEqualTo(0);
		return tReqMapper.selectByExample(tReqExample);
	}

	public List<TReq> selectUnpassedRequest() {
		TReqExample tReqExample = new TReqExample();
		Criteria createCriteria = tReqExample.createCriteria();
		createCriteria.andStateEqualTo(2);
		return tReqMapper.selectByExample(tReqExample);
	}

	public List<TReq> selectPassedRequest() {
		TReqExample tReqExample = new TReqExample();
		Criteria createCriteria = tReqExample.createCriteria();
		createCriteria.andStateEqualTo(1);
		return tReqMapper.selectByExample(tReqExample);
	}

	public List<TClient> selectAddByCCode(String cCode) {
		TClientExample tClientExample = new TClientExample();
		com.cjh.lms.pojo.TClientExample.Criteria criteria = tClientExample.createCriteria().andCCodeEqualTo(cCode);
		criteria.andCCodeEqualTo(cCode);
		return tClientMapper.selectByExample(tClientExample);
	}

	public List<LockCheckModel> showCheckList() {
		return showCheckListMapper.showChecklist();
	}

	public Boolean updateLockInfo(int requestCount, String cCode) {
		return tLockInfoMapper.updateLockInfo(requestCount, cCode);
	}

	public List<LockClientModel> getclientInfo() {
		return clientInfoMapper.getClientInfo();

	}
}
